#import <Foundation/Foundation.h>
#import <AFNetworking/AFNetworking.h>


// 网络请求类型
typedef NS_ENUM(NSInteger, RequestMethod) {
    RequestMethodGET,
    RequestMethodPOST,
    RequestMethodPUT,
    RequestMethodDELETE
};

// 网络请求回调
typedef void(^SuccessBlock)(id responseObject);
typedef void(^FailureBlock)(NSError *error);
typedef void(^ProgressBlock)(NSProgress *progress);

@interface NetworkManager : NSObject

/// 单例实例
+ (instancetype)sharedManager;

/// 基础URL
@property (nonatomic, copy, readonly) NSString *baseURL;

/// 请求超时时间(默认30秒)
@property (nonatomic, assign) NSTimeInterval timeoutInterval;

/// 配置请求头
- (void)configHTTPHeaderFields:(NSDictionary<NSString *, NSString *> *)headerFields;

/// 通用网络请求方法
/// @param method 请求方法
/// @param urlString 接口地址
/// @param parameters 请求参数
/// @param progress 进度回调
/// @param success 成功回调
/// @param failure 失败回调
- (NSURLSessionDataTask *)requestWithMethod:(RequestMethod)method
                                 urlString:(NSString *)urlString
                                 parameters:(id)parameters
                                   progress:(ProgressBlock)progress
                                    success:(SuccessBlock)success
                                    failure:(FailureBlock)failure;

/// GET请求
/// @param urlString 接口地址
/// @param parameters 请求参数
/// @param success 成功回调
/// @param failure 失败回调
- (NSURLSessionDataTask *)getWithUrlString:(NSString *)urlString
                                parameters:(id)parameters
                                   success:(SuccessBlock)success
                                   failure:(FailureBlock)failure;

/// POST请求
/// @param urlString 接口地址
/// @param parameters 请求参数
/// @param success 成功回调
/// @param failure 失败回调
- (NSURLSessionDataTask *)postWithUrlString:(NSString *)urlString
                                 parameters:(id)parameters
                                    success:(SuccessBlock)success
                                    failure:(FailureBlock)failure;

/// 上传文件
/// @param urlString 接口地址
/// @param parameters 请求参数
/// @param fileData 文件数据
/// @param fileName 文件名
/// @param mimeType 文件类型
/// @param progress 进度回调
/// @param success 成功回调
/// @param failure 失败回调
- (NSURLSessionDataTask *)uploadWithUrlString:(NSString *)urlString
                                   parameters:(id)parameters
                                     fileData:(NSData *)fileData
                                     fileName:(NSString *)fileName
                                     mimeType:(NSString *)mimeType
                                     progress:(ProgressBlock)progress
                                      success:(SuccessBlock)success
                                      failure:(FailureBlock)failure;

/// 取消所有请求
- (void)cancelAllRequests;

/// 根据URL取消请求
- (void)cancelRequestWithURLString:(NSString *)urlString;

@end
